<!DOCTYPE html>
<html lang="en">
    <head>
        {include file="public/header"}
        <script type="text/javascript">

        </script>
    </head>
    <body>
        <div class="wrapper">
            {include file="public/nav"}
            <div id="page-wrapper">
	            <div class="col-lg-12">
	                <h1 class="page-header">修改题目</h1>
	            </div>
                <div class="col-lg-3">{$data.pap_name}</div>
                <div class="col-lg-9">
                    <form id="form" class="form  form-horizontal" role="form" action="updatequestion" method="post">
                        <input type="hidden" name="pid" value="{$data.pap_id}">
                        <input type="hidden" name="chid" value="{$data.ch_id}">
                        
                        <div class="choice" id="choice">
                            <div class="col-lg-12">
                                <div class="form-group">
                                    <label>题目名称:</label>
                                    <input class="form-control" type="text" name="title" value="{$data.ch_title}">
                                </div>
                                <div class="form-group">
                                    <label>题目选项和答案:</label>
                                    <div class="answer-warp">
                                        <div class="answer-input" id="answer">
                                            {php} $sort = ['A','B','C','D','E']; {/php}
                                            {volist name="data.value" id="vo"}
                                            <div class="input-group">

                                                <span class="input-group-addon">
                                                    <input type="checkbox" name="result[]" {$vo.check} value="{$key}">
                                                </span>
                                                <span class="input-group-addon">{$sort[$key]}</span>
                                                <input type="text" class="form-control" name="options[]"  value="{$vo.option}">
                                            </div>
                                            {/volist}
                                        </div>
                                    </div>
                                    <div class="margin-top-10" style="margin-top:10px;">

                                        <a href="javascript:;" id="minus" class="btn btn-primary"><span class="fa fa-minus"></span></a>
                                        <a href="javascript:;" id="plus" class="btn btn-primary"><span class="fa fa-plus"></span></a>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </form>
                    <button class="btn btn-primary" id="submit">确定</button>

                </div>
            </div>
        </div>
        <div class="modal fade" tabindex="-1" role="dialog" id="modal">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">提示：</h4>
                    </div>
                    <div class="modal-body">
                        
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->        
        {include file="public/javascript"}

        <script type="text/javascript">
         var chars = ['A','B','C','D','E'];
         var num = {php}echo count($data['value']);{/php};
         var answer =$("#answer");
         var it = $(answer.children()[0]).clone();
         it.find('input[type = "checkbox"]')[0].checked = false;
         it.find('input[type = "text"]')[0].value = '';
         $("#plus").on('click',function(){
             temp = it.clone();
             if(num < chars.length){
                 span = temp.find("span");
                 item = temp.find("input");
                 $(item[0]).val(num);
                 $(span[1]).text(chars[num]);
                 num++;
                 answer.append(temp);

             }else{
                 
                 return;
             }
         });
         $("#minus").on('click',function(){
             var it = answer.children();
             console.log(it);
             if(it.length == 1 ){
                 return;
             }else{
                 console.log(1);
                 $(it[it.length-1]).remove();
                 num--;
             }

         });
        </script>        
        <script type="text/javascript">      
         ($("#submit").on('click',function(){
             $.ajax({
                 url : 'updatequestion.html?',
                 type : "post",
                 data : $("#form").serialize(),
                 dataType : 'html',
                 success : function(res){
                     _res = JSON.parse(res);
                     if(_res.error == 1 ){
                         modal = $("#modal");
                         modal.find('.modal-body').html('添加成功');
                         modal.modal('show');
                         modal.modal('show').on('hide.bs.modal',function(){
                             modal.find('.modal-body').html('');

                         });
                     }else{
                         modal = $("#modal");
                         modal.find('.modal-body').html('添加失败');
                         modal.modal('show');
                     }
                 },
                 error : function(){
                     modal = $("#modal");
                     modal.find('.modal-body').html('添加失败');
                     modal.modal('show');
                 }
                 
             });
         }));
        </script>
    </body>
</html>
